package com.pokemon.server;

import com.pokemon.dto.TrainerDTO;
import com.pokemon.services.TrainerService;
import java.util.List;
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;

/**
 *
 * @author Ladislav
 */
@WebService(endpointInterface="com.pokemon.services.TrainerService", serviceName="Trainer")
public class TrainerServiceImpl implements TrainerService {
    
    @Resource
    WebServiceContext wsCtx;
   
    TrainerService service;

    public TrainerService getService() {
        return service;
    }

    public void setService(TrainerService service) {
        this.service = service;
    }
    
    private String getClient(){
        MessageContext msgCtx = wsCtx.getMessageContext();
        HttpServletRequest req = (HttpServletRequest) msgCtx.get(MessageContext.SERVLET_REQUEST);
        return req.getRemoteHost();
    }

    
    

    public TrainerDTO addTrainer(TrainerDTO trainer) {
        service.addTrainer(trainer);
        return trainer;
    }

    public TrainerDTO getTrainer(Long id) {
        return service.getTrainer(id);
    }

    public TrainerDTO updateTrainer(TrainerDTO trainer) {
        service.updateTrainer(trainer);
        return trainer;
    }

    public TrainerDTO removeTrainer(TrainerDTO trainer) {
        service.removeTrainer(trainer);
        return trainer;
    }

    public List<TrainerDTO> getAllTrainers() {
        return service.getAllTrainers();
    }


}
